import { fields } from "./FieldUtil.js";

export function fieldSpan(col_width, width) {
  if (col_width > 4) {
    col_width = 4;
  } else if (col_width < 1) {
    col_width = 1;
  }
  let baseSpan = Math.round(24 / col_width);
  let span = baseSpan * (width || 1);
  return span > 24 ? 24 : span;
}

export function labelSpan(field_span) {
  switch (field_span) {
    case 6:
      return 4;
    case 8:
      return 4;
    case 12:
    case 18:
      return 2;
    case 24:
      return 2;
    default:
      if (v > 6) {
        return 4;
      } else if (v < 1) {
        return 1;
      }
  }
}

export function contentSpan(label_span) {
  return 24 - label_span;
}

/**
 * 
 * @param {*} vm 
 * @param {*} meta 
 * @returns 
 */
export function ctl_items(vm, meta) {
  if (meta && meta.items) {
    let items = meta.items.filter(x => {
      return (x.visible == null || x.visible == true)
        && vm.getState(x);
    });
    return items;
  } else {
    return [];
  }
}

export default {
  fieldSpan, labelSpan, contentSpan, fields, ctl_items
}